package com.example.agriculturemachine.ui.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.agriculturemachine.R;
import com.example.agriculturemachine.bean.ItemBean;

import java.util.List;

public class selectAdapter extends RecyclerView.Adapter<selectAdapter.InnerHolder> {

    private final List<ItemBean> mdata;

    @Override
    public selectAdapter.InnerHolder onCreateViewHolder(@NonNull  ViewGroup parent, int viewType) {
        View view = getView(parent, viewType);
        return new InnerHolder(view);
    }
    public selectAdapter(List<ItemBean> data){
        this.mdata=data;
    }
    @Override
    public void onBindViewHolder(@NonNull  selectAdapter.InnerHolder holder, int position) {
        holder.setData(mdata.get(position),position);
        holder.mcar_details.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnClickEvent.onClickCarDetails();
            }
        });

    }

    @Override
    public int getItemCount() {
        if (mdata!=null){
            return mdata.size();
        }
        return 0;
    }
    protected  View getView(ViewGroup parent, int viewType){
        View view=View.inflate(parent.getContext(), R.layout.car_item,null);
        return view;
    }
    public interface onClickEvent{
        void onClickCarDetails();
    }
    public onClickEvent mOnClickEvent;

    public onClickEvent getOnClickEvent() {
        return mOnClickEvent;
    }

    public void setOnClickEvent(onClickEvent onClickEvent) {
        mOnClickEvent = onClickEvent;
    }

    public class InnerHolder extends RecyclerView.ViewHolder {
        private final ImageView mstatus;
        private final TextView mtitle;
        private final TextView mcar_details;
        private final TextView mbinding;

        public InnerHolder(@NonNull View itemView) {
            super(itemView);
            mstatus = itemView.findViewById(R.id.status);
            mtitle = itemView.findViewById(R.id.title);
            mcar_details = itemView.findViewById(R.id.car_details);
            mbinding = itemView.findViewById(R.id.binding);
        }

        public void setData(ItemBean itemBean, int position) {
            mstatus.setImageResource(itemBean.status);
            mtitle.setText(itemBean.title);
            mbinding.setText(itemBean.binding);
        }
    }
    }

